# -*- coding: utf-8 -*-
import io
import sys
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') #改变标准输出的默认编码

import csv
dict_mashup_to_api = {

}
with open("mashup_api_style.csv", encoding='utf-8', mode="r", errors='ignore') as f:
    reader = csv.reader(f)
    for row in reader:
        if row[2] in dict_mashup_to_api:
            dict_mashup_to_api[row[2]] = dict_mashup_to_api[row[2]] + 1
        else:
            dict_mashup_to_api[row[2]] = 1
a1 = sorted(dict_mashup_to_api.items(), key=lambda x: x[1])
dict_mashup_to_api = dict(a1)
with open('被mashup使用的所有协议的出现次数.csv', "w", newline='', encoding='utf-8', errors='ignore') as f:
    writer = csv.writer(f)
    writer.writerow(['协议名称', '出现次数'])
    for i in dict_mashup_to_api.items():
        data = [i[0], i[1]]
        writer.writerow(data)